package com.softvan.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.softvan.bean.CityBean;
import com.softvan.dao.CityDao;
import com.softvan.entity.City;
import com.softvan.service.CityService;

@Service
public class CityServiceImpl implements CityService {
    @Autowired
    private CityDao cityDao;

    public List<CityBean> getAll(CityBean city) {
        if (city.getPage() != null && city.getRows() != null) {
            PageHelper.startPage(city.getPage(), city.getRows());
        }
        return cityDao.selectAll();
    }

    public CityBean getById(Integer id) {
        return cityDao.selectByPrimaryKey(id);
    }

    public void deleteById(Integer id) {
        cityDao.deleteByPrimaryKey(id);
    }

    public void save(CityBean country) {
        if (country.getId() != null) {
            cityDao.updateByPrimaryKey(country);
        } else {
            cityDao.insert(country);
        }
    }

    @Override
    public List<City> findAll(City city) {
        if (city.getPage() != null && city.getRows() != null) {
            PageHelper.startPage(city.getPage(), city.getRows());
        }
        return cityDao.findCitysAll();
    }
}
